package com.aaa.sys.controller;

import com.aaa.sys.entity.TabUser;
import com.aaa.sys.service.TabUserService;
import com.aaa.sys.service.impl.TabUserServiceImpl;
import com.util.LayData;
import com.util.PrintJsonData;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/login")
public class LoginServlet extends HttpServlet {
    private final TabUserService tabUserService = new TabUserServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 登录
        String username = req.getParameter("username");// 唯一的
        String password=req.getParameter("password");// 123456
        TabUser user = tabUserService.queryByNameAndPassword(username,password);
        // 用户的信息  有没有
        LayData success = null;
        HttpSession session = req.getSession();
        if(user!=null){
            // 登录成功
            // session
            session.setAttribute("user",user);
            success = LayData.success(true);

        }else{
            //

            success=LayData.error();
        }

        PrintJsonData.printData(resp,success);


    }
}
